#include <iostream>

class Vector2D {
private:
    double x, y;

public:
    // 构造函数
    Vector2D(double x_ = 0.0, double y_ = 0.0) : x(x_), y(y_) {}

    // 重载加法运算符，实现向量加法
    Vector2D operator+(const Vector2D& other) const {
        return Vector2D(x + other.x, y + other.y);
    }

    // 重载减法运算符，实现向量减法
    Vector2D operator-(const Vector2D& other) const {
        return Vector2D(x - other.x, y - other.y);
    }

    // 重载乘法运算符，实现数乘
    Vector2D operator*(double scalar) const {
        return Vector2D(x * scalar, y * scalar);
    }

    // 实现点乘
    double dotProduct(const Vector2D& other) const {
        return x * other.x + y * other.y;
    }

    // 重载<<运算符，使得可以通过cout打印
    friend std::ostream& operator<<(std::ostream& os, const Vector2D& vec) {
        os << "(" << vec.x << ", " << vec.y << ")";
        return os;
    }
};

int main() {
    Vector2D v1(1.0, 2.0);
    Vector2D v2(3.0, 4.0);

    Vector2D sum = v1 + v2;
    Vector2D diff = v1 - v2;
    Vector2D scaled = v1 * 2.0;
    double dotProd = v1.dotProduct(v2);

    std::cout << "v1: " << v1 << "\n";
    std::cout << "v2: " << v2 << "\n";
    std::cout << "Sum: " << sum << "\n";
    std::cout << "Difference: " << diff << "\n";
    std::cout << "v1 scaled by 2: " << scaled << "\n";
    std::cout << "Dot product of v1 and v2: " << dotProd << "\n";

    return 0;
}
